package org.wx.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * @description: ThreadLocal Test
 * @author: wangxun
 * @createDate: 2021/4/14
 * @version: 1.0
 */
@Slf4j
public class ThreadLocalTest {
    ThreadLocal tl = new ThreadLocal<String>();

    public static void main(String[] args) {
        final ThreadLocalTest threadLocalTest = new ThreadLocalTest();

        new Thread(() -> {
            threadLocalTest.tl.set(Thread.currentThread().getName());
            log.info("当前TL的内容：{}", threadLocalTest.tl.get());
            threadLocalTest.tl = null;
            System.gc();
            log.info("gc之后 当前TL的内容：{}", threadLocalTest.tl.get());
        },"t1").start();



        new Thread(() -> {
            threadLocalTest.tl.set(Thread.currentThread().getName());

            log.info("当前TL的内容：{}", threadLocalTest.tl.get());

        },"t2").start();;
    }
}
